﻿@model PagingDataSet<Thread>
@{
    var section = ViewData.Get<Section>("section", null);
    var categoryId = ViewData.Get<long>("categoryId", 0);
    var keyword = ViewData.Get<string>("keyword", null);
    var sortBy_BarThread = ViewData.Get<int>("sortBy_BarThread", 0);
    var sortBy_BarDateThread = ViewData.Get<int>("sortBy_BarDateThread", 0);
    var isSpecial = ViewData.Get<int>("isSpecial", 0);
    int index = 1;
    var times = ViewData.Get<string>("times", string.Empty);
}
@if (Model != null && Model.Any())
{
    foreach (var item in Model)
    {
        <div class="media">
            <div class="media-left">
                @Html.ShowUserAvatar(userId: item.UserId, htmlAttributes: new RouteValueDictionary { { "width", "50" }, { "height", "50" } })
            </div>
            <div class="media-body">
                <h5 class="media-heading">
                    <a href="@CachedUrlHelper.Action("ThreadDetail","Post",null,new RouteValueDictionary { { "threadId",item.ThreadId }})">
                        @item.Subject
                        @if (item.isEssential())
                        {
                            <span class="label label-danger">精华</span>
                        }
                        @if (isSpecial == 0)
                        {
                            if (item.IsSticky)
                            {
                                <span class="label label-danger">置顶</span>
                            }
                        }

                    </a>
                </h5>
                <ul class="list-inline text-muted">
                    <li><a href="@SiteUrls.Instance().MyHome(item.UserId)?type=home">@item.Author</a></li>
                    <li><i class="fa fa-clock-o" aria-hidden="true"></i> @item.DateCreated.ToFriendlyDate()</li>
                    @if (item.ThreadCategory != null)
                    {
                        <li><a href="javascript:;" class="jumptoThreadCategory" data-id="@item.ThreadCategory.CategoryId"><i class="fa fa-list-ul" aria-hidden="true" title="@item.ThreadCategory.CategoryName"></i> @HtmlUtility.TrimHtml(item.ThreadCategory.CategoryName, 10)</a></li>
                    }
                    <li class="pull-right"><i class="fa fa-commenting" aria-hidden="true"></i> @item.CommentCount</li>
                    <li class="pull-right"><i class="fa fa-eye" aria-hidden="true"></i> @item.HitTimes</li>
                    @if (item.LastModifiedUserId != 0)
                    {
                        <li>@UserIdToUserNameDictionary.GetDisplayName(item.LastModifiedUserId) 最后回复于 @item.LastModified.ToFriendlyDate()</li>
                    }
                </ul>
                @if (item.Attachments != null && item.Attachments.Count() > 0)
                    {
                    <div class="tn-chat-photo">
                        <ul class="tn-nine-squares list-unstyled clearfix">
                            @foreach (var img in item.Attachments)
                            {
                                if (img.MediaType != MediaType.Image)
                                {
                                    continue;
                                }
                                else
                                {
                                    <li class="tn-photo-item"><a class="tn-block" href="@CachedUrlHelper.Action("ThreadDetail","Post",null,new RouteValueDictionary { { "threadId",item.ThreadId }})"><img class="tn-block lazy" data-original="@img.GetDirectlyUrl("Small")" alt=""></a></li>
                                    {
                                        index++;
                                        if (index == 4)
                                        {
                                            break;
                                        }
                                    }
                                }

                            }
                        </ul>
                    </div>
                }
            </div>
        </div>
    }
    <div class="text-center">
        @Html.AjaxPagingButton(Model, "_ListThread", CachedUrlHelper.Action("_ListThread", "Post", null, new RouteValueDictionary {
    { "sectionId",section.SectionId }, {"categoryId",categoryId },
    { "keyword",keyword}, { "sortBy_BarThread", sortBy_BarThread },
    { "sortBy_BarDateThread", sortBy_BarDateThread }, { "isSpecial",isSpecial}
}))
    </div>
}
else
{
    <div class="text-center text-warning tn-mb-20 tn-mt-20">
        暂无任何贴子
    </div>
}
<script>
    $('.jumptoThreadCategory').on("click", function () {
        var $this = $(this);
        $('.threadCategory[data-id="' + $this.data('id') + '"]').click();
    })
</script>




@if (!string.IsNullOrEmpty(times))
{
    <script type="text/javascript">
    require(['jquery'], function ($) {
   
        $('.searchresult').html('@times');
        $('.searchresult').removeClass("hidden");
        $('.timecondition').addClass("hidden");
    })
    </script>
}
else
{
<script type="text/javascript">
    require(['jquery'], function ($) {
  
        $('.searchresult').addClass('hidden');
        $('.timecondition').removeClass("hidden");
    })
</script>
}